package com.sto.stoapp.activity;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;
import android.widget.TextView;

import com.sto.stoapp.adapter.BillFilterAdapter;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.util.BillFilterUtil;
import com.sto.stoapp.widget.StoHomeActivity;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created by wj on 2016-12-05.
 *
 * 拦截件展示界面
 */

public class StoBillFiterActivity extends StoHomeActivity {

    private ListView listView;
    private TextView emptyTV ,timeTV;
    private List<String> datas=new ArrayList<String>();
    private BillFilterAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.act_bill_filter);
        Bundle extras = getIntent().getExtras();
        this.setTitleBottom(R.string.filter, extras.getString("busiType"));

        listView= (ListView) findViewById(R.id.list_view);
        emptyTV= (TextView) findViewById(R.id.empty);
        timeTV= (TextView) findViewById(R.id.tv_time);

        adapter=new BillFilterAdapter(this,datas);
        listView.setAdapter(adapter);

        initDatas();
    }

    /**
     * 初始化数据
     */
    private void initDatas() {

        List<String> strs=BillFilterUtil.getFilters(this);
        if(strs.size()==0){
            listView.setEmptyView(emptyTV);
            timeTV.setVisibility(View.GONE);
        }else {
            long billTime=StoFilePreference.getInstance(this).getBillTime();
            timeTV.setVisibility(View.VISIBLE);
            timeTV.setText("最近拦截时间:"+long2Time(billTime));
            datas.addAll(strs);
            adapter.notifyDataSetChanged();
        }
    }

    /**
     * long转时间格式
     * @param l
     * @return
     */
    private String long2Time(long l){
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy年MM月dd HH:mm:ss");
        Date date=new Date(l);
        return sdf.format(date);
    }
}
